trigger createAutomaticCustomerPortal on Account (after insert) {
for (Account account  : trigger.new){  
    
   
     
     
if(account.RecordTypeId=='012E0000000cDcNIAU'){
string accountId=account.Id;
Contact contact =Database.query('Select Id from Contact where AccountId=:accountId');       
string NickName= account.PersonEmail.split('@').get(0);
User user = new User();

        if(NickName.length()<8){
        user.Alias =NickName.substring(0,NickName.length());
        }else{
        user.Alias =NickName.substring(0,8); 
        }
        user.ContactId=contact.Id;
        user.CommunityNickname = account.PersonEmail;
        user.CurrencyIsoCode='USD';
        user.DigestFrequency='N';
        user.DefaultGroupNotificationFrequency='N'; 
        user.Email =account.PersonEmail;
        user.EmailEncodingKey='UTF-8';
        user.Firstname = account.firstname;
        user.IsActive=true;
        user.Lastname = account.lastname;
        user.LanguageLocaleKey='en_US';
        user.LocaleSidKey='en_US';
        user.ProfileID = '00eL0000000QKIn'; 
        user.TimeZoneSidKey='America/New_york';
        user.Username = account.PersonEmail;          
Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerUserEmail= true;
user.setOptions(dlo);
Database.insert(user);
}
 }
}